package com.alibaba.citrus.cr.common.log;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 模块枚举值
 */
public enum ModuleEnum {
    /**
     * 0,
     */
    SYSTEM("0", "系统"),
    /**
     * 1: 主数据
     */
    MAIN_DATA("1", "主数据"),

    /**
     * 2:月度计划
     */
    MONTH_PLAN("2", "月度计划"),

    /**
     * 3：调拨一盘货
     */
    UNIFIED_INVENTORY("3", "调拨一盘货"),

    /**
     * 4：预报销售
     */
    FORECAST_SALES("4", "销售预报"),

    /**
     * 5：价格
     */
    PRICE("5", "价格"),

    /**
     * 6：活动
     */
    ACTIVITY("6", "活动"),

    /**
     * 7: 销售
     */
    SALES("7","销售");

    private String moduleId;

    private String moduleName;

    ModuleEnum(String moduleId, String moduleName) {
        this.moduleId = moduleId;
        this.moduleName = moduleName;
    }

    public String getModuleId() {
        return moduleId;
    }

    public String getModuleName() {
        return moduleName;
    }

    public static ModuleEnum ofModuleId(String moduleId) {
        if (StringUtils.isEmpty(moduleId)) {
            return null;
        }
        return Arrays.stream(values()).filter(moduleEnum -> moduleEnum.getModuleId().equals(moduleId)).findAny().orElse(null);
    }

    public static ModuleEnum ofModuleName(String moduleName) {
        if (StringUtils.isEmpty(moduleName)) {
            return null;
        }
        return Arrays.stream(values()).filter(moduleEnum -> moduleEnum.getModuleName().equals(moduleName)).findAny().orElse(null);
    }

    public static Map<String, String> getMap() {
        Map<String, String> map = new HashMap<>();
        Arrays.stream(values()).forEach(moduleEnum -> {
            map.put(moduleEnum.getModuleId(), moduleEnum.getModuleName());
        });
        return map;
    }
}
